//
//  LXTransverseSsrollView.m
//  LXLessDemo
//
//  Created by LX on 16/2/10.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LXTransverseSsrollView.h"
#import "LXImageAndLabView.h"

#define scrollSpeak 10
#define superViewSpeak 15

#define officScrollViewWidth 240

#define imageView_TAG 763483
@interface LXTransverseSsrollView(){
}
@property(nonatomic,strong)UIScrollView *mainScrollView;


@end
@implementation LXTransverseSsrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
-(void)settingEveryoneWatchingViewWithList:(NSArray *)list{
    CGFloat scrollCount = 3.0;
    
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:self.frame];
    self.mainScrollView.backgroundColor = [UIColor clearColor];
    self.mainScrollView.contentSize = CGSizeMake(0,0);
    [self addSubview:self.mainScrollView];
    
    int hSpeak = 1;
    CGFloat width = (CGRectGetWidth(self.bounds) - (scrollCount-1)*hSpeak)/scrollCount;
    for (int i = 0; i < list.count; i++) {
        UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(i * width + hSpeak*i, 0,width,CGRectGetHeight(self.bounds) - hSpeak )];
        bgImage.layer.masksToBounds = YES;
        [bgImage setUserInteractionEnabled:YES];
        bgImage.tag = i + imageView_TAG;
        [bgImage setImage:[UIImage imageNamed:list[i]]];//[UIImage imageNamed:@"watch"]
        [self.mainScrollView addSubview:bgImage];
        [bgImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgImageClick:)]];
        
    }
    
    
}
-(void)settingHotUserViewWithDatas:(NSArray *)datas{
    NSInteger scrollCount = datas.count;

    self.mainScrollView = [[UIScrollView alloc] initWithFrame:self.frame];
    self.mainScrollView.backgroundColor = [UIColor clearColor];
    self.mainScrollView.contentSize = CGSizeMake(CGRectGetHeight(self.bounds) *scrollCount + (scrollCount - 1) *scrollSpeak + superViewSpeak*2, CGRectGetHeight(self.bounds));
    [self.mainScrollView setShowsHorizontalScrollIndicator:NO];

    [self addSubview:self.mainScrollView];
    
    
    for (int i = 0; i < scrollCount; i++) {
        UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(i * CGRectGetHeight(self.bounds) + scrollSpeak*i + superViewSpeak, 0, CGRectGetHeight(self.bounds),CGRectGetHeight(self.bounds))];
        bgImage.layer.masksToBounds = YES;
        [bgImage setUserInteractionEnabled:YES];
        bgImage.layer.cornerRadius = 3.0;
        bgImage.tag = i + imageView_TAG;
        [bgImage setImage:[UIImage imageNamed:datas[i]]];
        [self.mainScrollView addSubview:bgImage];
        [bgImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgImageClick:)]];
        //滤镜
        UIView *alpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bgImage.bounds), CGRectGetHeight(bgImage.bounds))];
        alpView.backgroundColor =  [UIColor colorWithWhite:0.5 alpha:0.5];
        alpView.layer.cornerRadius = 3.0;

        [bgImage addSubview:alpView];
        
        UIImageView *headView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        [headView setImage:[UIImage imageNamed:datas[i]]];
        headView.layer.masksToBounds = YES;
        headView.layer.cornerRadius = CGRectGetHeight(headView.bounds)/2.0;
        headView.layer.borderColor = [[UIColor whiteColor] CGColor];
        headView.layer.borderWidth = 1.0;
        headView.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2.0, CGRectGetHeight(headView.bounds)/2.0 + 15);
        [bgImage addSubview:headView];
        
        
        UILabel *titleLab = [LXCommonUtils settingLabWithFrame:CGRectMake(0, 0, CGRectGetWidth(bgImage.bounds), 20)
                                                          text:[NSString stringWithFormat:@"%d查看发布列表",i+1]
                                                     textColor:[UIColor whiteColor]
                                                         fount:[UIFont boldSystemFontOfSize:13]];
        titleLab.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2,  CGRectGetMaxY(headView.frame)+CGRectGetHeight(titleLab.bounds)/2 + 5);
        [bgImage addSubview:titleLab];
        
        CGFloat speak = 7;//间隔
        LXImageAndLabView *userCountView = [[LXImageAndLabView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bgImage.bounds)/2 - speak/2.0, 8) image:nil text:[NSString stringWithFormat:@"%d321 Less",i*3] fount:8];
        userCountView.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2.0 - CGRectGetWidth(userCountView.bounds)/2.0 - speak/2.0, CGRectGetHeight(userCountView.bounds)/2.0 +  CGRectGetMaxY(titleLab.frame) + 7);
        [bgImage addSubview:userCountView];

        LXImageAndLabView *stopDateView = [[LXImageAndLabView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bgImage.bounds)/2 - speak/2.0, 8) image:nil text:[NSString stringWithFormat:@"%d124关注",i*3] fount:8];
        stopDateView.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2.0 + speak/2 + CGRectGetWidth(stopDateView.bounds)/2.0, userCountView.center.y);
        [bgImage addSubview:stopDateView];
        
        UIView *hLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0.5, CGRectGetHeight(stopDateView.bounds))];
        hLineView.backgroundColor =  [UIColor whiteColor];
        hLineView.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2.0, stopDateView.center.y);
        [bgImage addSubview:hLineView];
 
    }
}
-(void)settingOfficialActivesViewWithDatas:(NSArray *)datas{
    NSInteger scrollCount = datas.count;
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:self.frame];
    self.mainScrollView.backgroundColor = [UIColor clearColor];
    self.mainScrollView.contentSize = CGSizeMake(officScrollViewWidth *scrollCount + (scrollCount - 1) *scrollSpeak + superViewSpeak*2, CGRectGetHeight(self.bounds));
    [self.mainScrollView setShowsHorizontalScrollIndicator:NO];
    [self addSubview:self.mainScrollView];
    
    for (int i = 0; i < scrollCount; i++) {
        UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(i * officScrollViewWidth + scrollSpeak*i + superViewSpeak, 0, officScrollViewWidth,CGRectGetHeight(self.bounds))];
        bgImage.layer.masksToBounds = YES;
        [bgImage setUserInteractionEnabled:YES];
        bgImage.tag = i + imageView_TAG;
        bgImage.layer.cornerRadius = 3.0;
        [bgImage setImage:[UIImage imageNamed:datas[i]]];
        [self.mainScrollView addSubview:bgImage];
        [bgImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgImageClick:)]];
        UILabel *titleLab = [LXCommonUtils settingLabWithFrame:CGRectMake(0, 40, CGRectGetWidth(bgImage.bounds), 20)
                                                          text:[NSString stringWithFormat:@"%d点击创建列表",i*3]
                                                     textColor:[UIColor whiteColor]
                                                         fount:[UIFont boldSystemFontOfSize:14]];
        titleLab.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2, CGRectGetHeight(bgImage.bounds)/2 - 10);
        [bgImage addSubview:titleLab];
        
        CGFloat speak = 10;
        LXImageAndLabView *userCountView = [[LXImageAndLabView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bgImage.bounds)/2 - speak/2.0, 8) image:[UIImage imageNamed:@"userCount"] text:[NSString stringWithFormat:@"2%d32人参加",i*3] fount:8];
        userCountView.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2.0 - CGRectGetWidth(userCountView.bounds)/2.0 - speak/2.0, CGRectGetHeight(userCountView.bounds)/2.0 +  CGRectGetMaxY(titleLab.frame) + 15);
        [bgImage addSubview:userCountView];
        
        LXImageAndLabView *stopDateView = [[LXImageAndLabView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bgImage.bounds)/2 - speak/2.0, 8) image:[UIImage imageNamed:@"click"] text:[NSString stringWithFormat:@"2月%d日截至",i+4] fount:8];
        stopDateView.center = CGPointMake(CGRectGetWidth(bgImage.bounds)/2.0 + speak/2.0 + CGRectGetWidth(stopDateView.bounds)/2.0, CGRectGetHeight(userCountView.bounds)/2.0+  CGRectGetMaxY(titleLab.frame) + 15);
        [bgImage addSubview:stopDateView];
        
    }
    
}

-(void)bgImageClick:(UIGestureRecognizer *)sender
{
    NSInteger  index = sender.view.tag - imageView_TAG;
    NSLog(@"点击头像%ld",(long)index);
    if (self.selectBlock) {
        self.selectBlock([NSString stringWithFormat:@"点击%ld",(long)index]);
    }
}

@end
